from flask import jsonify
from .. import utils
from . import api

################################## System Information ##################################
@api.route('/get_uptime/<sn>/')
def get_uptime(sn):
    r=utils.exec_command(sn,'uptime')
    return jsonify(r)

@api.route('/get_mount/<sn>/')	#share
def get_mount(sn):
	r=utils.exec_command(sn, 'df -h')
	return jsonify(r)

@api.route('/get_system_build/<sn>/')	#share
def get_system_build(sn):
	r=utils.exec_command(sn, 'cat /var/state/system')
	return jsonify(r)

@api.route('/get_ps/<sn>/') #share
def get_ps(sn):
	r=utils.exec_command(sn, 'ps')
	return jsonify(r)

@api.route('/get_voltage/<sn>/')	#50
def get_voltage(sn):
	r=utils.exec_command(sn, 'ubus call ibled get_voltage')
	return jsonify(r)

################################## Operate System ##################################
@api.route('/opt_sysupgrade/<sn>/')
def opt_sysupgrade(sn):
	r=utils.exec_command(sn, 'curl -s http://wsg.f3322.net:9080/airmedia_info/HMSysUp.sh | sh')
	print r
	return jsonify(r)

@api.route('/opt_force_sysupgrade/<sn>/')
def opt_force_sysupgrade(sn):
	r=utils.exec_command(sn, 'curl -s http://115.29.151.181/logread_tool/upgrade/force_sysupgrade.sh | sh')
	return jsonify(r)

@api.route('/opt_reboot/<sn>/')
def opt_reboot(sn):
	r=utils.exec_command(sn, 'reboot')
	return jsonify(r)

@api.route('/opt_exe_cmd/<sn>/<paras>/')
def opt_exe_cmd(sn,paras):
	opt_exe_cmd_name = 'curl -s http://wsg.f3322.net:9080/airmedia_info/config/cmd.sh|sh -s '+paras
	r=utils.exec_command(sn, opt_exe_cmd_name)
	return jsonify(r)
